﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PPIDesktopClient.Entities;

namespace PPIDesktopClient.Controls.Project
{
    public partial class ProjectView : UserControl
    {
        private List<EVendor_Project> m_ListProjects;
        public List<EVendor_Project> ListProjects
        {
            set
            {
                m_ListProjects = value;
            }
        }
        private int m_SelectedProjectId;
        public int SelectedProjectId
        {
            get
            {
                return m_SelectedProjectId;
            }
            set
            {
                m_SelectedProjectId = value;
            }
        }

        
        public ProjectView()
        {
            InitializeComponent();
            m_SelectedProjectId = Int32.MinValue;
        }

        public void CleanData()
        {
            lblActualCostValue.Text = "";
            lblActualEndDateValue.Text = "";
            lblActualStartDateValue.Text = "";
            lblProjectName.Text = "";
            lblScheduledCostValue.Text = "";
            lblScheduledEndDateValue.Text = "";
            lblScheduledStartDateValue.Text = "";
            lblVendorName.Text = "";
        }

        public void LoadData()
        {
            CleanData();
            if (m_SelectedProjectId != Int32.MinValue)
            {
                EVendor_Project _SelectedProject = m_ListProjects.Find(ProjectById);
                if (_SelectedProject != null)
                {
                    lblActualCostValue.Text = _SelectedProject.ActualCost.ToString();
                    lblActualEndDateValue.Text = _SelectedProject.ActualEndDate.ToShortDateString();
                    lblActualStartDateValue.Text = _SelectedProject.ActualStartDate.ToShortDateString();

                    lblProjectName.Text = _SelectedProject.Name;

                    lblVendorName.Text = _SelectedProject.Vendor.Name;

                    lblScheduledCostValue.Text = _SelectedProject.ScheduledCost.ToString();
                    lblScheduledEndDateValue.Text = _SelectedProject.ScheduledEndDate.ToShortDateString();
                    lblScheduledStartDateValue.Text = _SelectedProject.ScheduledStartDate.ToShortDateString();

                    //lblStatusName.Text = _SelectedProject.Status.ProjectStatusId;
                    //lblTypeName.Text = _SelectedProject.Type.ProjectTypeId;
                }            
            }

        }

        private bool ProjectById(EVendor_Project s)
        {
            if (s.Vendor_ProjectId == m_SelectedProjectId)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }
}
